#ifndef FILEMODEL_H_
#define FILEMODEL_H_

#include "objectModel.h"
#include <obj.hpp>
#include <vector>
#include <map>
#include <cassert>
#include <iostream>

class FileModelException : public std::exception{
	private:
		std::string parser_message;

		virtual const char* what()const throw(){
			return parser_message.c_str();
		}
	public:

		FileModelException(const std::string& parse_error) : parser_message(parse_error){}
		virtual ~FileModelException()throw(){}
};

class FileModel:public ObjectModel{
	private:
		obj::obj_parser obj_parser;
		obj::mtl_parser mtl_parser;

		std::string mtlfile;
		std::string objfile;
		std::string path;
		std::string current;

		// Mtl parser functions
		void ambient_reflectivity_rgb_callback(obj::float_type r,obj::float_type g,obj::float_type b);

		void diffuse_reflectivity_rgb_callback(obj::float_type r,obj::float_type g,obj::float_type b);

		void specular_reflectivity_rgb_callback(obj::float_type r,obj::float_type g,obj::float_type b);

		void specular_exponent_callback(obj::float_type ns);

		void dissolve_factor_callback(obj::float_type d);

		void texture_map_diffuse_reflectivity_callback(const obj::options_type& options,const std::string& filename);

		void material_name_change(const std::string& name);

		// Obj parser functions
		void material_group_change(const std::string& name);

		void material_library_callback(const std::string& name);

		void geometric_vertex_callback(obj::float_type x, obj::float_type y, obj::float_type z);

		void vertex_normal_callback(obj::float_type x, obj::float_type y, obj::float_type z);

		void texture_vertex_callback(obj::float_type x, obj::float_type y);

		void triangular_face_callback(const obj::index_3_tuple_type& t1, const obj::index_3_tuple_type& t2, const obj::index_3_tuple_type& t3);

		void error_callback(unsigned int line,const std::string& message);
	public:
		FileModel(const std::string& path,const std::string& file);
		~FileModel();

		void loadModel();
};


#endif /* FILEMODEL_H_ */
